package de.rs.espresso.tools.gui.model;

import java.util.ArrayList;
import java.util.List;

import de.rs.espresso.interfaces.ICube;
import de.rs.espresso.interfaces.IGlobalInformation;
import de.rs.espresso.tools.gui.model.Constraint.ConstraintDirection;
import de.rs.espresso.tools.gui.model.Constraint.ConstraintType;

public class Field {

	public List<Integer> containedCubes = new ArrayList<Integer>();

	public int x, y;

	public Field(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public static List<Field> createFields(IGlobalInformation info) {

		int inputs = info.getNumberOfInputs();
		int xMax, yMax;

		if (inputs % 2 > 0) {
			xMax = (int) Math.sqrt(Math.pow(2, inputs + 1));
			yMax = (int) Math.sqrt(Math.pow(2, inputs - 1));
		} else {
			double sqrt = Math.sqrt(Math.pow(2, inputs));
			xMax = (int) sqrt;
			yMax = (int) sqrt;
		}

		List<Field> result = new ArrayList<Field>();

		//Change to xMax / yMax
		for (int x = 0; x < 4; x++) {
			for (int y = 0; y < 4; y++) {
				result.add(new Field(x, y));
			}
		}

		return result;

	}

	public void addCube(Integer i) {
		containedCubes.add(i);
	}

	public boolean contains(int c) {
		return containedCubes.contains(c);
	}
	
	public String toString() {
		return "{"+x+","+y+"}";
	}

}
